/**
 *
 */
package anysware.gwt.client.rest;

import java.util.EventObject;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.Response;

/**
 * TODO: doc me
 *
 * @author keke<keke@codehaus.org>
 * @revision $Revision: 103 $
 * @version
 */
public class CallbackEvent extends EventObject {
	public static enum Reason {
		/**
		 * Sending request failed
		 */
		ERROR,
		/**
		 * Unable send request
		 */
		FAILED,
		/**
		 * Sending request successfully.
		 */
		SUCCESS;
	}

	/**
	 *
	 */
	private static final long	serialVersionUID	= 290056988210506740L;
	private Throwable	      error;
	private final Reason	  reason;
	private Request	          request;
	private Response	      response;

	public CallbackEvent(final Object source, final Request request, final Response response) {
		super(source);
		this.request = request;
		this.response = response;
		reason = Reason.SUCCESS;
	}

	public CallbackEvent(final Object source, final Request request,
	        final Throwable error) {
		super(source);
		this.request = request;
		this.error = error;
		reason = Reason.ERROR;
	}

	public CallbackEvent(final Object source, final Throwable error) {
		super(source);
		this.error = error;
		reason = Reason.FAILED;
	}

	/**
	 * @return the error
	 */
	public Throwable getError() {
		return error;
	}

	/**
	 * @return the reason
	 */
	public Reason getReason() {
		return reason;
	}

	/**
	 * @return the request
	 */
	public Request getRequest() {
		return request;
	}

	/**
	 * @return the response
	 */
	public Response getResponse() {
		return response;
	}
}
